home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gas_251.zip / bin_251 / opcodes / alpha-dis.c < prev    next >
C/C++ Source or Header  |  1994-01-06  |  5KB  |  179 lines

  1. /* Instruction printing code for the Alpha
  2.    Copyright (C) 1993 Free Software
  3.  
  4. Foundation, Inc. Contributed by Cygnus Support. 
  5.  
  6. Written by Steve Chamberlain (sac@cygnus.com) 
  7.  
  8. This file is part of libopcodes. 
  9.  
  10. This program is free software; you can redistribute it and/or modify it under
  11. the terms of the GNU General Public License as published by the Free
  12. Software Foundation; either version 2 of the License, or (at your option)
  13. any later version. 
  14.  
  15. This program is distributed in the hope that it will be useful, but WITHOUT
  16. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  17. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  18. more details. 
  19.  
  20. You should have received a copy of the GNU General Public License along with
  21. This program; if not, write to the Free Software Foundation, Inc., 675
  22.  Mass Ave, Cambridge, MA 02139, USA.  
  23. */
  24.  
  25. #include "dis-asm.h"
  26. #define DEFINE_TABLE
  27. #include "alpha-opc.h"
  28.  
  29.  
  30. /* Print one instruction from PC on INFO->STREAM.
  31.    Return the size of the instruction (always 4 on alpha). */
  32.  
  33. int
  34. print_insn_alpha(pc, info)
  35.     bfd_vma         pc;
  36.     struct disassemble_info *info;
  37. {
  38.   alpha_insn     *insn;
  39.   unsigned  char            b[4];
  40.   void           *stream = info->stream;
  41.   fprintf_ftype   func = info->fprintf_func;
  42.   int             given;
  43.   int             status ;
  44.   int found = 0;
  45.   
  46.   status = (*info->read_memory_func) (pc, (bfd_byte *) &b[0], 4, info);
  47.   if (status != 0) {
  48.     (*info->memory_error_func) (status, pc, info);
  49.     return -1;
  50.   }
  51.   given = (b[0]) | (b[1] << 8) | (b[2] << 16) | (b[3] << 24);
  52.  
  53.   func (stream, "%08x %2x\t", given, (given>>26) & 0x3f);
  54.   
  55.   for (insn = alpha_insn_set;
  56.        insn->name && !found;
  57.        insn++)
  58.     {
  59.       switch (insn->type)
  60.     {
  61.     case MEMORY_FORMAT_CODE:
  62.       if ((insn->i & MEMORY_FORMAT_MASK) 
  63.           ==(given & MEMORY_FORMAT_MASK))
  64.         {
  65.           func (stream, "%s\t%s, %d(%s)",
  66.               insn->name,
  67.               alpha_regs[RA(given)],
  68.               OPCODE (given) == 9 ? DISP(given) * 65536 : DISP(given),
  69.               alpha_regs[RB(given)]);
  70.           found = 1;
  71.         }
  72.       break;
  73.     case BRANCH_FORMAT_CODE:
  74.       if ((insn->i & BRANCH_FORMAT_MASK)
  75.           == (given & BRANCH_FORMAT_MASK))
  76.         {
  77.           func (stream, "%s\t%s, ",
  78.               insn->name,
  79.               alpha_regs[RA(given)]);
  80.           (*info->print_address_func) (BDISP(given) * 4 + pc + 4, info);
  81.           found = 1;
  82.         }
  83.       break;
  84.  
  85.     case MEMORY_BRANCH_FORMAT_CODE:
  86.       if ((insn->i & MEMORY_BRANCH_FORMAT_MASK) 
  87.           == (given & MEMORY_BRANCH_FORMAT_MASK) )
  88.         {
  89.           if (given & (1<<15)) 
  90.         {
  91.           func (stream, "%s\t%s, (%s), %d", insn->name,
  92.               alpha_regs[RA(given)],
  93.               alpha_regs[RB(given)],
  94.               JUMP_HINT(given));
  95.         } 
  96.           else 
  97.         {
  98.           /* The displacement is a hint only, do not put out
  99.              a symbolic address.  */
  100.           func (stream, "%s\t%s, (%s), 0x%lx", insn->name,
  101.               alpha_regs[RA(given)],
  102.               alpha_regs[RB(given)],
  103.                   JDISP(given) * 4 + pc + 4);
  104.         }
  105.           found = 1;
  106.         }
  107.  
  108.       break;
  109.     case OPERATE_FORMAT_CODE:
  110.       if ((insn->i & OPERATE_FORMAT_MASK)
  111.           == (given & OPERATE_FORMAT_MASK)) 
  112.         {
  113.           if (OP_OPTYPE(insn->i) == OP_OPTYPE(given)) 
  114.         {
  115.           if (OP_IS_CONSTANT(given)) {
  116.             func (stream, "%s\t%s, 0x%x, %s", insn->name,
  117.                 alpha_regs[RA(given)],
  118.                 LITERAL(given),
  119.                 alpha_regs[RC(given)]);
  120.           } else {
  121.             func (stream, "%s\t%s, %s, %s", insn->name,
  122.                 alpha_regs[RA(given)],
  123.                 alpha_regs[RB(given)],
  124.                 alpha_regs[RC(given)]);
  125.           }
  126.           found = 1;
  127.         }
  128.         }
  129.           
  130.       break;
  131.     case FLOAT_FORMAT_CODE:
  132.       if ((insn->i & OPERATE_FORMAT_MASK)
  133.           == (given & OPERATE_FORMAT_MASK)) 
  134.         {
  135.           func (stream, "%s\tf%d, f%d, f%d", insn->name,
  136.               RA(given),
  137.               RB(given),
  138.               RC(given));
  139.           found = 1;
  140.         }
  141.  
  142.       break;
  143.     case PAL_FORMAT_CODE:
  144.       if (insn->i == given)
  145.         {
  146.           func (stream, "call_pal %s", insn->name);
  147.           found = 1;
  148.         }
  149.  
  150.       break;
  151.     case FLOAT_MEMORY_FORMAT_CODE:
  152.       if ((insn->i & MEMORY_FORMAT_MASK) 
  153.           ==(given & MEMORY_FORMAT_MASK))
  154.         {
  155.           func (stream, "%s\tf%d, %d(%s)",
  156.               insn->name,
  157.               RA(given),
  158.               OPCODE (given) == 9 ? DISP(given) * 65536 : DISP(given),
  159.               alpha_regs[RB(given)]);
  160.           found = 1;
  161.         }
  162.       break;
  163.     case FLOAT_BRANCH_FORMAT_CODE:
  164.       if ((insn->i & BRANCH_FORMAT_MASK)
  165.           == (given & BRANCH_FORMAT_MASK))
  166.         {
  167.           func (stream, "%s\tf%d, ",
  168.               insn->name,
  169.               RA(given));
  170.           (*info->print_address_func) (BDISP(given) * 4 + pc + 4, info);
  171.           found = 1;
  172.         }
  173.       break;
  174.     }
  175.     }
  176.     
  177.   return 4;
  178. }
  179.